package com.itboye.shop.me.qianbao;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.shop.R;
import com.itboye.shop.base.BaseActivity;
import com.itboye.shop.net.ResultEntity;
import com.itboye.shop.presenter.UserPresenter;
import com.itboye.shop.presenter.YuEPresenter;
import com.itboye.shop.util.loadutil.IsUtilUid;
import com.itboye.shop.util.loadutil.MAlert;

import java.util.Observable;
import java.util.Observer;

/**
 * 添加银行卡3
 */
public class AddBankCardThreeActivity extends BaseActivity implements Observer{
    TextView tvTitle;
    ImageView back;

    EditText add_bank03_code;
    Button add_bank03_ok;
    YuEPresenter presenter;
    String names;
    String type;
    String yhk_type;
    String phone;

    UserPresenter userPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_bank_card_three);
        tvTitle.setText("绑定账户");

        presenter=new YuEPresenter(this);
        userPresenter=new UserPresenter(this);
        names = getIntent().getStringExtra("name");
        type = getIntent().getStringExtra("type");
        yhk_type = getIntent().getStringExtra("yhk_type");
        phone = getIntent().getStringExtra("phone");
    }
    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.add_bank03_ok:
                if (add_bank03_code.getText().toString() == null || add_bank03_code.getText().toString().equals("")) {
                    MAlert.alert("请填写验证码", Gravity.CENTER);
                } else {
                    showProgressDialog("请稍后...", true);
                    userPresenter.YanZhengverificationCode("+86",phone,add_bank03_code.getText().toString(),2+"");
                }
                break;
            default:
                break;
        }
    }
    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            if(entity.getEventType()==UserPresenter.yanzheng_code_success){

                presenter.onByWalletBind(IsUtilUid.isUid(), names, type,yhk_type);
            }
            if(entity.getEventType()==UserPresenter.yanzheng_code_fail){
                MAlert.alert(entity.getData(), Gravity.CENTER);
            }
            if (entity.getEventType() == presenter.BANG_success) {
                MAlert.alert(entity.getData(), Gravity.CENTER);
                finish();
                // 发送广播通知界面结束
                Intent intent1 = new Intent("tianjia.exit");
                sendBroadcast(intent1);
            }
            if (entity.getEventType() == presenter.BANG_fail) {
                MAlert.alert(entity.getData(), Gravity.CENTER);
            }
        }
        try {
            closeProgressDialog();
        } catch (Exception e) {
        }
    }
}
